/**
 * 路由基础配置
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import Iview from 'iview';

import routerpath from "./routerpath"
import store from "./../store/store"
import axios from 'axios'

const _config = require('./../../config/config')

Vue.use(Iview)
Vue.use(VueRouter)

/**
 * 定义路由
 */
const router = new VueRouter({
//	mode:"history",
	routes: routerpath,
	linkActiveClass: "active", 
	base:"/readbook/"
});

/**
 * 路由跳转之前处理函数
 */
router.beforeEach((to, from, next) => {
	Iview.LoadingBar.start();
	next();
	/* if(to.path!="/login"){
		validate(() => {
			next();
		});	
	}else{
		next();
	} */
});

/**
 * 路由跳转之后处理函数
 */
router.afterEach(rt => {
	Iview.LoadingBar.finish();
});


function validate1(backcall) {
	axios.get("/host/readbook/userInfo.html")
	.then(result => {
		if(result.login){
			backcall();
		}else{
			window.location.href =_config._WEB_SERVER + "/readbook/#/login";
		}
	})
	.catch(() => {
		window.location.href =_config._WEB_SERVER + "/readbook/#/login";
	})
}
export default router;